package com.extension.company.presenter.my;

import com.extension.company.common.mvp.BasePresenter;
import com.extension.company.contract.AddressListContract;
import com.extension.company.contract.home.OnlineWaitForPaymentContract;
import com.extension.company.model.entity.AddressListData;
import com.extension.company.model.my.AddressListMode;

import java.util.List;

public class AddressListPresenter extends BasePresenter<AddressListMode, AddressListContract.View> {
	@Override
	public AddressListMode createModel() {
		return new AddressListMode();
	}

	@Override
	protected void onViewDestroy() {

	}

	/**
	 * 功能：获取收货的地址
	 */
	public void requestAddressList() {
		model.mAddListRequest(new AddressListContract.AddressListCallBack() {

			@Override
			public void AddressListCallBackSuccessful(List<AddressListData.DataBean.AddressBean> list) {
				if (null != getView()) {
					getView().dataCallBackSuccess(list);  // 回到给View
				}
			}

			@Override
			public void AddressListCallBackFaile(String msg) {


			}
		});
	}

	/**
	 * 功能：删除某个item
	 *
	 * @param id item的id
	 */
	public void deleteAddress(String id) {

		model.deleteAddressList(id, new AddressListContract.deleteItemCallBack() {
			@Override
			public void deleteItem(String msg) {
				if (null != getView()) {
					getView().deleteSuccess(msg);
				}
			}
		}); //删除某个地址
	}

	/**
	 * 设置默认收货地址
	 *
	 * @param addressId 地址的id
	 */
	public void defaultAddress(int addressId) {
		model.setDefaultAddress(addressId, new AddressListContract.defaultAddressCallBack() {
			@Override
			public void defaultAddressCallBack(boolean isSetDefaultSuceess) {
				if (null != getView()) {
					getView().defaultAddress(isSetDefaultSuceess);
				}
			}
		});
	}


}
